package com.zj.osm.view.map.setmap;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.zj.osm.R;
import com.zj.osm.view.BaseActivity;
import com.zj.utils.map.GoogleTileSource;
import com.zj.utils.utils.utilcode.SPUtils;
import com.zj.utils.view.TitleBar;

import java.util.List;

import static com.zj.osm.utils.Configuration.MAP_TILE_SOURCE;

public class SetMapSourceActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {

    private static final int TILE_SOURCE_GOOGLE_HYBRID = 0;
    private static final int TILE_SOURCE_GOOGLE_SAT = 1;
    private static final int TILE_SOURCE_GOOGLE_ROADS = 2;
    private static final int TILE_SOURCE_GOOGLE_TERRAIN = 3;
    private static final int TILE_SOURCE_GOOGLE_TERRAIN_HYBRID = 4;
    private static final int TILE_SOURCE_AUTO_NAVI_VECTOR = 5;
    private static final int TILE_SOURCE_TIAN_DITU_IMG = 6;
    private static final int TILE_SOURCE_TIAN_DITU_CIA = 7;
    private static final int TILE_SOURCE_BAIDU_MAP = 8;
    private RadioButton radio1, radio2, radio3, radio4, radio5, radio6, radio7, radio8, radio9;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_map_source);
        initView();
    }

    private void initView() {
        TitleBar mSetMapTitleBar = findViewById(R.id.setMapTitleBar);
        mSetMapTitleBar.setTitle("选择地图");
        mSetMapTitleBar.setBackImageVisiable(true);
        RadioGroup setMapRg = findViewById(R.id.setMapRg);
        setMapRg.setOnCheckedChangeListener(this);


        radio1 = findViewById(R.id.radio1);
        radio2 = findViewById(R.id.radio2);
        radio3 = findViewById(R.id.radio3);
        radio4 = findViewById(R.id.radio4);
        radio5 = findViewById(R.id.radio5);
        radio6 = findViewById(R.id.radio6);
        radio7 = findViewById(R.id.radio7);
        radio8 = findViewById(R.id.radio8);
        radio9 = findViewById(R.id.radio9);

        String mapSource = SPUtils.getInstance().getString(MAP_TILE_SOURCE);
        defaultRb(mapSource);

    }

    private void defaultRb(String mapSource) {
        switch (mapSource) {
            //谷歌卫星混合
            case GoogleTileSource.TILE_SOURCE_GOOGLE_HYBRID:
                radio1.setChecked(true);
                break;
            //谷歌卫星
            case GoogleTileSource.TILE_SOURCE_GOOGLE_SAT:
                radio2.setChecked(true);
                break;
            //谷歌地图
            case GoogleTileSource.TILE_SOURCE_GOOGLE_ROADS:
                radio3.setChecked(true);
                break;
            //谷歌地形
            case GoogleTileSource.TILE_SOURCE_GOOGLE_TERRAIN:
                radio4.setChecked(true);
                break;
            //谷歌地形带标注
            case GoogleTileSource.TILE_SOURCE_GOOGLE_TERRAIN_HYBRID:
                radio5.setChecked(true);
                break;
            //高德地图
            case GoogleTileSource.TILE_SOURCE_AUTO_NAVI_VECTOR:
                radio6.setChecked(true);
                break;
            //影像地图 _W是墨卡托投影  _c是国家2000的坐标系
            case GoogleTileSource.TILE_SOURCE_TIAN_DITU_IMG:
                radio7.setChecked(true);
                break;
            //影像标注 _W是墨卡托投影  _c是国家2000的坐标系
            case GoogleTileSource.TILE_SOURCE_TIAN_DITU_CIA:
                radio8.setChecked(true);
                break;
            //百度
            case GoogleTileSource.TILE_SOURCE_BAIDU_MAP:
                radio9.setChecked(true);
                break;
        }
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        switch (checkedId) {
            case R.id.radio1:
                setTileSource(TILE_SOURCE_GOOGLE_HYBRID);
                break;
            case R.id.radio2:
                setTileSource(TILE_SOURCE_GOOGLE_SAT);
                break;
            case R.id.radio3:
                setTileSource(TILE_SOURCE_GOOGLE_ROADS);
                break;
            case R.id.radio4:
                setTileSource(TILE_SOURCE_GOOGLE_TERRAIN);
                break;
            case R.id.radio5:
                setTileSource(TILE_SOURCE_GOOGLE_TERRAIN_HYBRID);
                break;
            case R.id.radio6:
                setTileSource(TILE_SOURCE_AUTO_NAVI_VECTOR);
                break;
            case R.id.radio7:
                setTileSource(TILE_SOURCE_TIAN_DITU_IMG);
                break;
            case R.id.radio8:
                setTileSource(TILE_SOURCE_TIAN_DITU_CIA);
                break;
            case R.id.radio9:
                setTileSource(TILE_SOURCE_BAIDU_MAP);
                break;
        }
    }

    /**
     * 根据编号获取地图源然后设置为共享参数
     *
     * @param page 编号
     */
    private void setTileSource(int page) {
        List<String> iTileSources = GoogleTileSource.getmTileSources();
        SPUtils.getInstance().put(MAP_TILE_SOURCE, iTileSources.get(page));
    }
}
